package day01.cn.itcast.reflect;

import day01.cn.itcast.doMain.Person;

import java.lang.reflect.Field;

/**
 * @author Lenovo
 */
public class ReflectDemo2 {
    public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException {
        Class personClass=Person.class;
        Field[] fields=personClass.getFields();
        for(Field field:fields){
            System.out.println(field);
        }
        System.out.println("--------");
        Field a=personClass.getField("a");
        Person p=new Person();
        Object value=a.get(p);
        System.out.println(value);
        a.set(p,"张三");
        System.out.println(p);
        System.out.println("--------");
        Field[] declaredFields=personClass.getDeclaredFields();
        for(Field declareField:declaredFields){
            System.out.println(declareField);
        }
        Field d= personClass.getDeclaredField("d");
        d.setAccessible(true);
        Object value2=d.get(p);
        System.out.println(value2);
    }

}
